//
//  Tool_UserDefaultInfo.m
//  AndonFunction
//
//  Created by 宣佚 on 14/11/30.
//  Copyright (c) 2014年 刘宣佚. All rights reserved.
//

#import "Utils_UserDefaultInfo.h"

@implementation Utils_UserDefaultInfo

/**
 *  获取iOS设备唯一标示
 *
 *  @return iOS设备唯一标示
 */
+(NSString *)GetMobileIdentifer {
    NSString *modelID = [[NSUserDefaults standardUserDefaults] objectForKey:@"MobileIdentifer"];
    if ([modelID isEqualToString:@""] || modelID == nil) {
        CFUUIDRef uuidObj = CFUUIDCreate(nil);
        NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(nil, uuidObj));
        NSString *str = [uuidString stringByReplacingOccurrencesOfString:@"-"
                                                              withString:@""];
        NSString *lowerStr = [str lowercaseString];
        [[NSUserDefaults standardUserDefaults] setObject:lowerStr forKey:@"MobileIdentifer"];
        modelID = [[NSUserDefaults standardUserDefaults] objectForKey:@"MobileIdentifer"];
    }
    return modelID;
}

/**
 *  获取用户唯一标示
 *
 *  @return 用户唯一标示
 */
+(NSString *)GetUserIdentifer:(NSString *)UserIdentity {
    NSString *userID = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserIdentifer"];
    if ([userID isEqualToString:@""] || userID == nil) {
        [[NSUserDefaults standardUserDefaults] setObject:UserIdentity forKey:@"UserIdentifer"];
        userID = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserIdentifer"];
    }
    return userID;
}

/**
 *  设置用户唯一标示
 */
+(void)SetUserIdentifer:(NSString *)UserIdentity {
    [[NSUserDefaults standardUserDefaults] setObject:UserIdentity forKey:@"UserIdentifer"];
}

/**
 *  获取用户AccessKey
 *
 *  @return 用户AccessKey
 */
+(NSString *)GetUserAccessKey:(NSString *)AccessKey {
    NSString *accessKey = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserAccessKey"];
    if ([accessKey isEqualToString:@""] || accessKey == nil) {
        [[NSUserDefaults standardUserDefaults] setObject:AccessKey forKey:@"UserAccessKey"];
        accessKey = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserAccessKey"];
    }
    return accessKey;
}

/**
 *  设置用户AccessKey
 */
+(void)SetUserAccessKey:(NSString *)AccessKey {
    [[NSUserDefaults standardUserDefaults] setObject:AccessKey forKey:@"UserAccessKey"];
}

/**
 *  获取用户DeviceToken
 *
 *  @return 用户DeviceToken
 */
+(NSString *)GetUserDeviceToken:(NSString *)DeviceToken {
    NSString *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserDeviceToken"];
    if ([deviceToken isEqualToString:@""] || deviceToken == nil) {
        [[NSUserDefaults standardUserDefaults] setObject:DeviceToken forKey:@"UserDeviceToken"];
        deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserDeviceToken"];
    }
    return deviceToken;
}

/**
 *  设置用户DeviceToken
 */
+(void)SetUserDeviceToken:(NSString *)DeviceToken {
    [[NSUserDefaults standardUserDefaults] setObject:DeviceToken forKey:@"UserDeviceToken"];
}

@end
